function dlComplete(id)
{
	 var json = {
             "id": id,
             "state": "1"
         };
         $.ajax({
             //提交数据的类型 POST GET
             type:"POST",
             //提交的网址
             url:path + '/wx/res/judgesion/updateConsultationState.html',
             contentType: "application/json; charset=utf-8",   //内容类型
             //提交的数据
             data:JSON.stringify(json),
             //返回数据的格式
             datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
             //在请求之前调用的函数
             beforeSend:function(){loading('<span style="color:#fbf9f8">正在提交，请稍等...</span>');},
             //成功返回之后调用的函数
             success:function(data){
             	
                 if(data.code == '0000')
                 {
                     closeLoading();
                     //处理成功
                     showTip("<span style=\"color:#fbf9f8\">处理成功</span>","info",2000);
                     $('#dlComplete' + id).hide();
                 }
                 else{
                 	showTip(data.msg,"info",2000);
                     closeLoading();
                 }

             }   ,
             //调用执行后调用的函数
             complete: function(XMLHttpRequest, textStatus){
             },
             //调用出错执行的函数
             error: function(){
                 //请求出错处理

                 alertx("请求异常123123",closed);
             }
         });	
	
	
}
function loadData(delState)
{
    var itemIndex = 0;
	var indexct = 1;
	var indexcty = 1;
	var page = 1;
    var tabLoadEndArray = [false, false, false];
    var tabLenghtArray = [28, 15, 47];
    var tabScroolTopArray = [0, 0, 0];
    $('#weichuli').html('');
    $('#yichuli').html('');
    $('.khfxWarp').html('');
    // dropload
    var dropload = $('.khfxWarp').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
            domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData: '<div class="dropload-noData">已无数据</div>'
        },
        loadDownFn: function (me) {
            setTimeout(function () {
                if (tabLoadEndArray[itemIndex]) {
                    me.resetload();
                    me.lock();
                    me.noData();
                    me.resetload();
                    return;
                }
                var result = '';
                
                //奖励细则
                if(delState == '0')//未处理
                {
                    $.getJSON(path + '/wx/res/judgesion/consultation_reservation.html?page=' + page +"&state=0", function (data) {
                        //遍历json中的每个entry
                    	var isHasData = 0;
                    	result = '';

                    	//业绩奖励
                        $.each(data, function (entryindex, entry) {
                            result
                            = ''
                            + '      <div class="item item-'+indexcty+'">'
                            + '      	<p><i>姓名：</i><b>'+entry['name']+'</b></p>'
                            + '         <p><i>联系电话：</i><b>'+encodeMobile(entry['mobile'])+'</b></p>'
                            + '        	<p><i>预约时间：</i><b>'+entry['createDate']+'</b></p>'
                            + '        	<hr />'
                            + '        	<a href="tel:'+entry['mobile']+'" class="l-a">联系TA</a>'
                            + '        	<a class="r-a" id="dlComplete'+entry['id']+'" onclick="dlComplete('+entry['id']+')">处理完成</a>'
                            + '      </div>';
                            indexcty++;
                            isHasData = 1;
                            $('#weichuli').append(result);
                        });
                        page++;
                        if(isHasData == 0)
                        {
                            tabLoadEndArray[itemIndex] = true;
                            
                        }	
                        me.resetload();
                    });                  	
                }
                else//已处理
                {
                    $.getJSON(path + '/wx/res/judgesion/consultation_reservation.html?page=' + page +"&state=1", function (data) {
                        //遍历json中的每个entry
                    	var isHasData = 0;
                    	result = '';

                    	//业绩奖励
                        $.each(data, function (entryindex, entry) {
                            result
                            = ''
                            + '      <div class="item item-'+indexct+'">'
                            + '      	<p><i>姓名：</i><b>'+entry['name']+'</b></p>'
                            + '         <p><i>联系电话：</i><b>'+encodeMobile(entry['mobile'])+'</b></p>'
                            + '        	<p><i>预约时间：</i><b>'+entry['createDate']+'</b></p>'
                            + '        	<p><i>处理时间：</i><b>'+entry['updateDate']+'</b></p>'
                            + '       </div>';
                            indexct++;
                            isHasData = 1;
                            $('#yichuli').append(result);
                        });
                        page++;
                        if(isHasData == 0)
                        {
                            tabLoadEndArray[itemIndex] = true;
                            
                        }	
                        
                        me.resetload();
                    });                 	
                }
              //邀请奖励
            }, 500);
        }
    });

}
function changeState(state)
{
	delState = state;
	dropload.resetload();
}
function encodeMobile(mobile)
{
	
	return mobile.substring(0,3)+"****"+mobile.substring(8,11);;  
}
$(function () {

	loadData('0');
	
	function changeState(state)
	{
		delState = state;
		dropload.resetload();
	}
    function encodeMobile(mobile)
    {
    	
    	return mobile.substring(0,3)+"****"+mobile.substring(8,11);;  
    }
    $('.tabHead span').on('click', function () {

        tabScroolTopArray[itemIndex] = $(window).scrollTop();
        var $this = $(this);
        itemIndex = $this.index();
        $(window).scrollTop(tabScroolTopArray[itemIndex]);
        
        $(this).addClass('active').siblings('.tabHead span').removeClass('active');
        $('.tabHead .border').css('left', $(this).offset().left + 'px');
        $('.khfxPane').eq(itemIndex).show().siblings('.khfxPane').hide();

        if (!tabLoadEndArray[itemIndex]) {
            dropload.unlock();
            dropload.noData(false);
        } else {
            dropload.lock('down');
            dropload.noData();
        }
        dropload.resetload();
    });
});